<?php
class ProductController extends CommonController{
	public function index(){
		$db=M('News');
		if(isset($_GET['category_id'])){
			$where='category_id='.intval($_GET['category_id']);
			$category_where='id='.intval($_GET['category_id']);
		}else{
			$where='category_id in(2,6,7,8)';
			$category_where='id in(2,6,7,8)';
		}
		$count=$db->where($where)->count();
		$p=new Page($count);
		$newsList=M('News')->where($where)->limit($p->firstRow.','.$p->listRows)->select();
		$category_list=M('NewsCategory')->where($category_where)->oneField('name','id')->select();
		$this->assign('category_list',$category_list);
		$this->assign('page',$p->show());
		$this->assign('newsList',$newsList);
		$this->display();
	}
	public function read(){
		$id=intval($_GET['id']);
		$news=M('News')->where("id={$id}")->find();
		$this->assign('news',$news);
		$this->display();
	}
}